﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WineModel;
using System.Data;
using System.Web.Script.Serialization;
using System.Collections;
using System.Data.SqlClient;

namespace WineDAL
{
   public  class WineCommentDAL
    {
       SQLHelper helper = new SQLHelper();
       /// <summary>
       /// 显示评论
       /// </summary>
       /// <returns></returns>
       public ArrayList CommentShow(int id)
       {
           SqlParameter par = new SqlParameter("@id", id);
           DataTable table = helper.ExecDataTable_Proc("Comment_Show",par);
           JavaScriptSerializer jss = new JavaScriptSerializer();
           System.Collections.ArrayList dic = new System.Collections.ArrayList();
           foreach (DataRow dr in table.Rows)
           {
               System.Collections.Generic.Dictionary<string, object> drow = new System.Collections.Generic.Dictionary<string, object>();
               foreach (DataColumn dc in table.Columns)
               {
                   drow.Add(dc.ColumnName, dr[dc.ColumnName]);
               }
               dic.Add(drow);
           }
           return dic;           
       }
       /// <summary>
       /// 添加用户评论
       /// </summary>
       /// <param name="UsersID"></param>
       /// <param name="GoodsID"></param>
       /// <param name="CommentContent"></param>
       /// <param name="CommentStar"></param>
       /// <returns></returns>
       public int AddComments(int UsersID,int GoodsID,string CommentContent,int CommentStar)
       {
           SqlParameter[] pare = new SqlParameter[]{
            new SqlParameter("@UsersID",UsersID),
            new SqlParameter("@GoodsID",GoodsID),
            new SqlParameter("@CommentContent",CommentContent),
            new SqlParameter("@CommentStar",CommentStar)
           };
           return helper.ExecNonquery_Proc("Comments_Add", pare);
       }
    }
}
